<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>function_sort.php</title>
<style>
div, body, pre{
font-family:source code pro,consolas"微软雅黑", Verdana, Geneva, sans-serif;
}
</style>
</head>

<body>
<div>
<?
require_once '../inc.php';

$filename=$_REQUEST['filename'];
if(empty($filename)){
	
	$filename="I:/AppServ/www/_doll/inc/lib.php";
	}
//$str=_frdf($filename);
//$c="[^{}]";
$a=_chars_each(file($filename));

function _chars_each($string) {
	if(is_array($string)) {
		foreach($string as $key => $val) {
			$string[$key] =_chars_each($val) ;
		}
	} else {
	$string =str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $string);
	//$string =str_replace(array(" ","\t"),array("&nbsp;","&nbsp;&nbsp;&nbsp;&nbsp;"),$string);
	}
	return $string;
}
function _repalce_space_tab($string){
    return str_replace(array(" ","\t"),array("&nbsp;","&nbsp;&nbsp;&nbsp;&nbsp;"),$string);	
}

$reta=array();

foreach($a as $k=>$v){
	if( preg_match("/^\}/s" , $v) ){
		$reta[]= ($v)."[-function_end-]\n";	
	}else if( preg_match("/^function\s[^\n]{1,}\}\s*$/" , $v) ){
	    $reta[]="". ($v)."[-function_end-]\n";	
	}else{
		$reta[]= preg_replace(array("/^&lt;\?(php){0,}[^\n]{0,}\n/","/\?&gt;[^\n]{0,}\n/"),array("//?\n","\n"),$v);	
		}	
}
$result=implode($reta,"");


//$result=preg_match_all("/(function\s{1,}.*?)\[\-function_end\-\]/s",  $result,$ms);
// secho($ms[1]);
$result=preg_split("/\[\-function_end\-\]/s",$result);
//sort($result);
//secho($result);

$newresult=array();
$aFuncs=array();
foreach($result as $k=>$v){
	preg_match("/function\s+([0-9a-zA-Z_]{1,})/",$v,$ms);
	 
	$aFuncs[]=$ms[1];
	$key=$ms[1];
	$newresult[$key]=$v;
}

$result=$newresult;
$result=array_flip($result);
asort($result);
$result=array_flip($result);
$count=0;

echo "<pre>";
foreach($result as $k=>$v){
	
    echo '<font style="color:red;font-weight:bold;font-size:20px;">//*--------function*start------</font></br>';
	echo _mkcstr('//*function name<b>[ID:'.Clhighlight::StFormatNumber($count)
	.']</b>:'.
	_mkcstr($k)->High()->Add('$$'."\n")->Val()
	.'')->High("red",16)->Val();
	echo preg_replace(array("/^[\s\n]*/","/\/\/{1,}\*{1,}.{0,}\n/"),array("",""),$v);	
	echo '<font style="color:red;font-weight:bold;font-size:20px;">//*--------function*end------</font></br></br>';
$count++;	
}
echo "</pre>";
//echo htmlspecialchars($str);

function _write_self_to_html_ex(){
	if(empty($url)){
	    preg_match("/\/{1}([a-zA-Z0-9\._]{1,})$/i",$_SERVER['PHP_SELF'],$ms);
		$url = $ms[1];
	}
	echo '<iframe src="'.$url.'?action=w" style="display:none;"></iframe>';	
	if($_REQUEST['action']=='w'){
		echo _fwf($url.".html",file_get_contents("http://".$_SERVER[SERVER_NAME].":".$_SERVER[SERVER_PORT]."/".$_SERVER['PHP_SELF']))?"ok":"error";	
	}
}
_write_self_to_html();

?>
</div> 
 
</body>
</html>